package net.kleinhenz.norabase.client;

import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.grid.ListGrid;
import com.smartgwt.client.widgets.grid.ListGridRecord;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
import com.smartgwt.client.widgets.layout.HLayout;

public class BattlegroupGrid extends ListGrid {

	public BattlegroupGrid() {
		super();
		setShowRecordComponents(true);
		setShowRecordComponentsByCell(true);
		setCanRemoveRecords(false);
	}

	@Override
	protected Canvas createRecordComponent(final ListGridRecord record, Integer colNum) {

		String fieldName = this.getFieldName(colNum);

		if (fieldName.equals("icons")) {
			HLayout recordCanvas = new HLayout(3);
			recordCanvas.setHeight(22);
			recordCanvas.setAlign(Alignment.LEFT);
			
			ImgButton removeImg = new ImgButton();
			removeImg.setShowDown(false);
			removeImg.setShowRollOver(false);
			removeImg.setLayoutAlign(Alignment.LEFT);
			removeImg.setSrc("/icons/remove.png");
			removeImg.setPrompt("Remove from current Battlegroup");
			removeImg.setHeight(16);
			removeImg.setWidth(16);
			removeImg.addClickHandler(new ClickHandler() {
				public void onClick(ClickEvent event) {
					removeData(record);
				}
			});

			recordCanvas.addMember(removeImg);
			return recordCanvas;
		} else {
			return null;
		}
	};
}